﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.AspNet.SignalR.Infrastructure;
using PruebasCesar.Models;

namespace PruebasCesar.Hubs
{
    [HubName("moneda")]
    public class MonedasHub : Hub
    {
        public void ObtenerMonedas()
        {
            var monedas = new List<Moneda>
            {
                new Moneda {Id = 1, Nombre = "Dolar Oficial", Compra = 5.39m, Venta = 5.54m},
                new Moneda {Id = 2, Nombre = "Dolar Cueva", Compra = 7.39m, Venta = 7.54m},
                new Moneda {Id = 3, Nombre = "Dolar Blue", Compra = 9.39m, Venta = 9.54m},
                new Moneda {Id = 4, Nombre = "Euro", Compra = 10.39m, Venta = 11.54m},
                new Moneda {Id = 5, Nombre = "Libra", Compra = 10.39m, Venta = 11.54m},
                new Moneda {Id = 6, Nombre = "Real", Compra = 2.39m, Venta = 2.54m},
                new Moneda {Id = 7, Nombre = "Guarani", Compra = 521.39m, Venta = 524.54m}
            };

            var ran = new Random();

            foreach (var m in monedas)
            {
                m.Compra = Convert.ToDecimal(ran.Next(3, 15)) + Convert.ToDecimal(ran.NextDouble());
                m.Venta = m.Compra + Convert.ToDecimal(ran.NextDouble());
            }

            Clients.All.cotizacionMonedas(monedas.ToArray());
        }
    }
}